package com.aote.util;

import com.browsesoft.Entity;
import com.browsesoft.EntityManager;

/**
 * 单值帮助
 */
public final class SingleValueHelper {
	/**
	 * 获得单值的字符值
	 */
	public static final String getStringValue(final String name) {
		try {
			Entity entity = EntityManager.getInstance().getEntity(
					"singlevalue", "name", name);
			return (String) entity.getAttributes().get("value");
		} catch (Exception e) {
			throw new RuntimeException("单值不存在：" + name);
		}
	}

	/**
	 * 获得单值的double值
	 */
	public static final double getDoubleValue(final String name) {
		String str = getStringValue(name);
		try {
			return Double.parseDouble(str);
		} catch (Exception e) {
			throw new RuntimeException("单值不是数字：" + name);
		}
	}
	
	/**
	 * 获得单值的整形值
	 */
	public static final int getIntValue(final String name) {
		String str = getStringValue(name);
		try {
			return Integer.parseInt(str);
		} catch (Exception e) {
			throw new RuntimeException("单值不是整数：" + name);
		}
	}
	
	/**
	 * 更新单值
	 */
	public static final void UpdataNameOfValue(final String name,String value){
			
			try {
				Entity entity = EntityManager.getInstance().getEntity(
						"singlevalue", "name", name);
				entity.getAttributes().get("name");
				entity.getAttributes().put("value",value);
				entity.update();
			} catch (Exception e) {
				throw new RuntimeException(e.getMessage());
			}
	}
}
